<?php
// calendar.php
// check if month and year values exist

//calendar.php
//Check if the month and year values exist
if ((!isset($_GET['month'])) && (!isset($_GET['year']))) {
$month = date ("n");
$year = date ("Y");
} else {
$month = $_GET['month'];
$year = $_GET['year'];
}

// echo($month . $year);
// viewed month
$timestamp = mktime (0,0,0,$month,1,$year);
$monthname = date("F", $timestamp);

?>
<table style="width:105px; border-collapse:collapse;" border="1" cellpadding="3" cellspacing="0" bordercolor="#000000">
<tr style="background: #FFBC37;">
<td colspan="7" style="text-align:center;" onmouseover="this.style.background='#FFBC37' " onmouseout="this.style.background='#FF00FF' ">
<span style="font-weight: bold;"><?php echo $monthname . " " . $year; ?> </span>
</td>
</tr>
<tr>

<td style="text-align: center; width: 15px;" onmouseover="this.style.background='#FECE6E'" onmouseout="this.style.background='#FFBC37'"><span style="font-weight: bold;">Sun</span>
</td>
<td style="text-align: center; width: 15px;" onmouseover="this.style.background='#FECE6E'" onmouseout="this.style.background='#FFBC37'"><span style="font-weight: bold;">Mon</span>
</td>
<td style="text-align: center; width: 15px;" onmouseover="this.style.background='#FECE6E'" onmouseout="this.style.background='#FFBC37'"><span style="font-weight: bold;">Tue</span>
</td>
<td style="text-align: center; width: 15px;" onmouseover="this.style.background='#FECE6E'" onmouseout="this.style.background='#FFBC37'"><span style="font-weight: bold;">Wed</span>
</td>
<td style="text-align: center; width: 15px;" onmouseover="this.style.background='#FECE6E'" onmouseout="this.style.background='#FFBC37'"><span style="font-weight: bold;">Thu</span>
</td>
<td style="text-align: center; width: 15px;" onmouseover="this.style.background='#FECE6E'" onmouseout="this.style.background='#FFBC37'"><span style="font-weight: bold;">Fri</span>
</td>
<td style="text-align: center; width: 15px;" onmouseover="this.style.background='#FECE6E'" onmouseout="this.style.background='#FFBC37'"><span style="font-weight: bold;">Sat</span>
</td>

</tr>

<?php
$monthstart = date("w",$timestamp); // day of week
$startday = -$monthstart;
$lastday = date("d",mktime(0,0,0,$month,0,$year));
// calculate number of rows
$numrow = ceil(($monthstart + $lastday)/7);

for ($i=0;$i<$numrow;$i++) // follow row
{

?>

<tr style="background: #FFBC37;" >

<?php

for ($j=0;$j<7;$j++) // follow column
{
$startday++;

if (($startday <=0) || ($startday > $lastday) )
{// display blank page
?>
<td>&nbsp;</td>
<?php

}
else
{
if ($startday==date("j") && $month==date("n") && $year==date("Y"))
{
// bold and change color of this present day
?>
<td onmouseover="this.style.background='#FECE6E'" onmouseout="this.style.background='#FFBC37'" ><span style="font-weight:bold;">
<?php
echo($startday);
?>
</span></td>
<?php
}
else
{
?>
<td onmouseover="this.style.background='#FECE6E'" onmouseout="this.style.background='#FFBC37'" ><span>
<?php
echo($startday);
?>
</span></td>
<?php

}

}

}

?>

</tr>

<?php

}


?>

</table>